package com.example.test_demo.async;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

/**
 * @program: test_demo
 * @description:
 * @author: yanghua
 * @create: 2021-09-15 17:32
 **/
@Component
public class AsyncDemo {

    @Async
    public Future<String> asynItem1(){
        System.out.println("one start");
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("one end");
        return new AsyncResult<>("hello word 1");
    }

    @Async
    public Future<String> asynItem2(){
        System.out.println("two start");
        return new AsyncResult<>("hello word 2");
    }

}
